﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NTUTMessagerServer
{
    public class LoginModel
    {
        public List<LoginEntry> loginList = new List<LoginEntry>();

        public LoginEntry AddLoginEntry(String account, String reportip, String realip, String publicKey)
        {
            LoginEntry loginEntry = new LoginEntry();
            loginEntry.account = account;
            loginEntry.ReportIp = reportip;
            loginEntry.RealIp = realip;
            loginEntry.publicKey = publicKey;

            loginList.Add(loginEntry);

            return loginEntry;
        }

        public LoginEntry RemoveLoginEntry(String ip)
        {
            foreach (LoginEntry loginEntry in loginList)
            {
                if (ip.Contains(loginEntry.RealIp) || loginEntry.RealIp.Contains(ip)) 
                {
                    loginList.Remove(loginEntry);

                    return loginEntry;
                    break;
                }
            }

            return null;
        }

        public LoginEntry isOnline(String account)
        {
            foreach (LoginEntry loginEntry in loginList)
            {
                if (loginEntry.account == account)
                {
                    return loginEntry;
                }
            }
            return null;
        }
    }

    public class LoginEntry
    {
        public String account;
        public String ReportIp;
        public String RealIp;
        public String publicKey;
    }
}
